%note 28-feb-08. new climatological model of Patrick was used 
% to correct daily Julia drift 
% the actual model is run on karma:/home/mnair/projects/ace/driftmodel
% the drift model file downloaded to c:\manoj\project\ace\julia_drift.txt
% this file was used to correct Julia drift
% The variable w_climate in Julia_PLP.mat is
% w_climate=(w-julia_model_drift');

load c:\manoj\projects\ace\Julia_W_new w Julia_W;
load C:\Manoj\projects\ace\solar_flux_new.mat fday euvac;

fid = fopen('c:\manoj\projects\ace\f107_drift.txt','wt');
ndays = 0;
for i = 1:1002,
    k = find(fday == Julia_W(i).fday);
    if ~isempty(k),
        ndays=ndays+1;
    [yy,mm,dd]=datevec(datenum(Julia_W(i).fday)+datenum(2000,1,1));   
    s = dayofyear(yy,mm,dd);
    f107 = euvac(k);
%         eej_str = ['eej_plot -o test.txt -l 284 -s ' sprintf('%6.2f ',s)...
%         ' -e ' sprintf('%6.2f ',f107) ' -p t'];
    fprintf(fid,'%3d %6.2f\n', s,f107);
    
    end;
end;
%     display(eej_str);
%     dos(eej_str);
%     fid = fopen('test.txt','rt');
%     for j = 1:8,fgetl(fid);end;
%     [A,count] = fscanf(fid,'%f',[3,inf]);
%     if count == 0,
%         fclose all;
%         break;
%     end;
%     fclose(fid);
%     eej_climat(i,:,:,:) = A';
%     end;
% end;
%     
% for i = 1:749,
% %plot(fday_julia(i,:)-floor(fday_julia(i,:)),w(i,:),'r');
% kk = interp1((eej_climat(i,:,1)+4.25)/24,eej_climate_1(i,:)*170,fday_julia(i,:)-floor(fday_julia(i,:)));
% w_climate(i,:) = w(i,:)-kk;
% end;

load c:\manoj\projects\ace\Julia_W_new
data = load('c:\manoj\projects\ace\drift_julia.txt');
julia_model_drift = reshape(data(:,4),[132,1002]);
julia_lt_fday = fday(1,:) - (floor(fday(1,1))+5/24);
julia_model_drift([1:13 108:end],:) = NaN;

for i = 300:1002,
%   subplot(211);
    plot(julia_lt_fday,w(i,:),'b','LineWidth',2);
    set(gca,'FontSize',16);
    hold on;
    plot(julia_lt_fday,julia_model_drift(:,i),'r','LineWidth',2);
    datetick;
    xlabel('LT Hours');
    ylabel('Julia Verical Drift m.s^{-1}');
    title(datestr(Julia_W(i).fday+datenum(2000,1,1)));
    legend('Observed','Modeled');
    hold off;
%     subplot(212);
%     L = isnan(w(i,:));
%     model_data = julia_model_drift(:,i)';
%     model_data(L) = NaN;
%     plot(julia_lt_fday,w(i,:)-model_data);
%     datetick;
    pause;
end;

data = load('c:\manoj\projects\ace\drift_julia.txt');
w_model = reshape(data(:,4),[132,1002]);
julia_model_drift = w_model';
w_climate = w-julia_model_drift;
%%%%%%save c:\manoj\projects\ace\Julia_W_new

